package com.concurrent.chapter1.concurrent02;

import java.util.concurrent.Semaphore;

public class Service {
	private Semaphore semaphore = new Semaphore(1);
	public void testMethod() {
		try {
			semaphore.acquireUninterruptibly();
			System.out.println(Thread.currentThread().getName() + " begin time=" + System.currentTimeMillis());
			for (int i = 0; i < Integer.MAX_VALUE/50; i++) {
				String newString = new String();
				Math.random();
			}
			System.out.println(Thread.currentThread().getName() + " end time=" + System.currentTimeMillis());
			semaphore.release();
		} catch (Exception e) {
			System.out.println(Thread.currentThread().getName() + " 进入了catch");
			e.printStackTrace();
		}
	}
}
